#region Using References

using System;
using Beaker.OpenCube.Mapping;

#endregion

namespace Beaker.OpenCube.Game.Converters
{
	/// <summary>
	/// Converter that can convert between a string and generator options
	/// </summary>
	public class GeneratorOptionsConverter
		: IValueConverter
	{
		/// <summary>
		/// Convert from NBT value to a Generator Options value.
		/// </summary>
		/// <param name="nbtValue">The NBT value to convert to a Generator Options value.</param>
		/// <returns>Generator Options.</returns>
		public object FromNbtToLocal( object nbtValue )
		{
			if( nbtValue is string )
			{
				var text = (string)nbtValue;
				if( string.IsNullOrEmpty( text ) )
					return null;

				GeneratorOptions options;

				if( GeneratorOptions.TryParse( text, out options ) )
					return options;

				throw new FormatException( "Failed to parse " + text );
			}

			throw new InvalidOperationException();
		}

		/// <summary>
		/// Convert from Generator Options value to a NBT value.
		/// </summary>
		/// <param name="localValue">The Generator Options value to convert to a NBT value.</param>
		/// <param name="targetType">The target type</param>
		/// <returns>
		/// A NBT value.
		/// </returns>
		/// <exception cref="System.NotImplementedException"></exception>
		public object FromLocalToNbt( object localValue, Type targetType )
		{
			throw new NotImplementedException();
		}
	}
}